import { registerAs } from '@nestjs/config';

export default registerAs('redis', () => ({
  host: process.env.REDIS_HOST || 'localhost',
  port: parseInt(process.env.REDIS_PORT, 10) || 6379,
  password: process.env.REDIS_PASSWORD,
  db: parseInt(process.env.REDIS_DB, 10) || 0,
  prefix: process.env.REDIS_PREFIX || 'resume:', // 键名前缀
  ttl: parseInt(process.env.REDIS_TTL, 10) || 60 * 60 * 24 * 7, // 默认7天
  retryStrategy: (times: number) => {
    return Math.min(times * 100, 3000); // 重试间隔最大3秒
  },
  reconnectOnError: (err: Error) => {
    const targetError = 'READONLY';
    if (err.message.includes(targetError)) {
      return true;
    }
    return false;
  },
})); 